Pelican是Python写的静态网页生成器,GitHub Pages是Github提供的免费空间,支持自定义域名,支持Markdown语法。
安装Pelican
sudo easy_install pelican markdown
创建目录
cd ~
mkdir pelican
pelican-quickstart
配置Pelican
Welcome to pelican-quickstart v3.4.0.
This script will help you create a new Pelican-based website.
Please answer the following questions so this script can generate the files
needed by Pelican.
> Where do you want to create your new web site? [.]
> What will be the title of this web site? Mordern mainframer
> Who will be the author of this web site? mainframer
> What will be the default language of this web site? [en] zh
> Do you want to specify a URL prefix? e.g., http://example.com (Y/n)
> What is your URL prefix? (see above example; no trailing slash) http://mainframer.github.io
> Do you want to enable article pagination? (Y/n)
> How many articles per page do you want? [10]
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n)
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n)
> Do you want to upload your website using FTP? (y/N)
> Do you want to upload your website using SSH? (y/N)
> Do you want to upload your website using Dropbox? (y/N)
> Do you want to upload your website using S3? (y/N)
> Do you want to upload your website using Rackspace Cloud Files? (y/N)
> Do you want to upload your website using GitHub Pages? (y/N) Y
> Is this your personal page (username.github.io)? (y/N) Y
Done. Your new project is available at /Users/Heros/pelican
下载风格包pelican-themes与插件包pelican-plugins
git clone git://github.com/getpelican/pelican-themes.git
git clone git://github.com/getpelican/pelican-plugins.git
配置pelicanconf.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
AUTHOR = u'mainframer'
AUTHOR_EMAIL = u'54xiaowoniu@sina.cn'
SITENAME = u'Modern Mainframer'
SITEURL = 'http://mainframer.github.io'
# Disqus
DISQUS_SITENAME = u"mainframer"
# Content path
PATH = 'content'
PAGE_PATHS = ['pages']
ARTICLE_PATHS = ['articles']
STATIC_PATHS = ['images', 'files']
EXTRA_PATH_METADATA = {
'files/robots.txt': {'path': 'robots.txt'},
'images/favicon.ico': {'path': 'favicon.ico'},
}
TIMEZONE = 'Asia/Shanghai'
DEFAULT_METADATA = (
)
DEFAULT_LANG = u'zh'
DEFAULT_DATE_FORMAT = ('%Y-%m-%d')
TAGLINE = 'Heros come and go but legends are forever .'
ARTICLE_URL = ('articles/{slug}.html')
ARTICLE_SAVE_AS = ('articles/{slug}.html')
PAGE_LANG_SAVE_AS = False
# Blogroll
LINKS = (
('IBM知识中心', 'http://www-01.ibm.com/support/knowledgecenter'),
)
# Social widget
SOCIAL = (
('mainframer@Github', 'https://github.com/mainframer'),
('mainframer@Linkedin','https://www.linkedin.com/in/mainframer'),
)
# Feed
FEED_DOMAIN = SITEURL
FEED_ALL_ATOM = 'feeds/all.atom.xml'
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
TRANSLATION_FEED_ATOM = None
# Sitemap
SITEMAP = {
'format': 'xml',
'priorities': {
'articles': 1,
'pages': 0.9,
'indexes': 0.8,
},
'changefreqs': {
'indexes': 'daily',
'articles': 'daily',
'pages': 'weekly'
}
}
# Theme
THEME = 'pelican-themes/zurb-F5-basic'
DEFAULT_PAGINATION = 10
MD_EXTENSIONS = (['codehilite(css_class=highlight)', 'extra',
'fenced_code', 'tables', 'sane_lists'])
# Plugin
PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = [ 'sitemap', 'gravatar' ]
DEFAULT_PAGINATION = 10
# Uncomment following line if you want document-relative URLs when developing
RELATIVE_URLS = False
|
配置 publishconf.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
# This file is only used if you use `make publish` or
# explicitly specify it as your config file.
import os
import sys
sys.path.append(os.curdir)
from pelicanconf import *
SITEURL = 'http://mainframer.github.io'
RELATIVE_URLS = False
FEED_ALL_ATOM = 'feeds/all.atom.xml'
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
DELETE_OUTPUT_DIRECTORY = True
DISQUS_SITENAME = u"mainframer"
# Following items are often useful when publishing
#DISQUS_SITENAME = ""
#GOOGLE_ANALYTICS = ""
|
撰写一篇文章
cd content
mkdir articles files images pages
vim articles/使用Pelican + Markdown + GitHub Pages写博客.md
Author: mainframer
Slug: 使用Pelican + Markdown + GitHub Pages写博客
Title: 使用Pelican + Markdown + GitHub Pages写博客
Tags: Pelican, Markdown,GitHub Pages
Date: 2014-10-25
Category: Others
生成robots.txt与favicon.ico
vim files/robots.txt
User-agent: *
Sitemap: http://mainframer.github.io/sitemap.xml
配置Disqus
在Disqus上注册一个用户并生成一个站点mainframer.disqus.com;
设置mainframer.disqus.com站点使其允许域名mainframer.github.io;
设置以上配置文件为DISQUS_SITENAME = u"mainframer",mainframer为站点ID
创建GitHub Pages
直接创建一个新的repo,但是其名称必须与ID相同,并加上github.io或github.com后缀。 就我而言,就必须创建一个repo名为mainframer.github.io
创建好GitHub Pages之后,生成Blog静态HTML文件
cd ~/pelican
make html
pelican /Users/Heros/pelican/content -o /Users/Heros/pelican/output -s /Users/Heros/pelican/pelicanconf.py WARNING: AUTHOR_SAVE_AS is set to False Done: Processed 1 article(s), 0 draft(s) and 0 page(s) in 0.18 seconds.
进入output目录,将生成好的静态HTML文件上传到GitHub Pages站点mainframer.github.io
cd output
git init
git remote add origin https://github.com/mainframer/mainframer.github.io.git
git add -A
git commit -m "Update Blog"
git push -u origin master
Comments !